function minSubArrayLen(s, nums) {
  let l = 0, r = -1; // nums [l..r] 滑动窗口
  let sum = 0
  let res = nums.length + 1
  while (l < nums.length) {
    if (r + 1 < nums.length && sum < s) {
      sum += nums[++r]
    } else {
      sum -= nums[l++]
    }
    if (sum >= s) {
      res = Math.min(res, r - l + 1)
    }
  }
  if (res === nums.length + 1) {
    return 0
  }
  return res
}

const r = minSubArrayLen(8, [1, 2, 3, 4, 8, 5])
console.log(r)